package com.lcf.app.shiro.component;

import com.lcf.app.shiro.common.MyException;
import com.lcf.common.web.Result;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authz.AuthorizationException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author ChenFei
 * @date 2021/11/2
 */
@RestControllerAdvice
public class ExceptionsHandler {

    @ExceptionHandler(MyException.class)
    public Result<String> myException(MyException e) {
        return Result.fail(e.getErrorMsg());
    }

    @ExceptionHandler(AuthorizationException.class)
    public Result<String> authorizationException(AuthorizationException e) {
        return Result.fail(e.getMessage() + " [ 权限不足 ] ");
    }

    @ExceptionHandler(IncorrectCredentialsException.class)
    public Result<String> incorrectCredentialsException(IncorrectCredentialsException e) {
        return Result.fail(e.getMessage() + " [ 密码验证异常 ] ");
    }
}
